package ruide_info_mvc.base.model.request;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.util.Date;

/**
 * 公共请求Bean
 * @ClassName BaseRequestBean
 * @Author wangBo
 * @Date 2019/7/20 0020 下午 8:38
 * @Version 1.0
 */
public class BaseRequestBean {

    // 请求参数
    protected String reqParams;

    // 操作人
    protected String operatorUserId;

    // 操作时间
    protected Date updateDate;

    // 创建时间
    protected Date createDate;

    public String getReqParams() {
        return reqParams;
    }

    public void setReqParams(String reqParams) {
        this.reqParams = reqParams;
    }

    public String getOperatorUserId() {
        return operatorUserId;
    }

    public void setOperatorUserId(String operatorUserId) {
        this.operatorUserId = operatorUserId;
    }

    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public BaseRequestBean toBean(Class<? extends BaseRequestBean> clazz) throws IOException, JsonParseException, JsonMappingException {
        ObjectMapper objectMapper = new ObjectMapper();
        BaseRequestBean obj = null;
        if (null != this.getReqParams() && this.getReqParams().length() > 0) {
            obj = objectMapper.readValue(this.getReqParams() , clazz);
        }
        return obj;
    }

    @Override
    public String toString() {
        return "BaseRequestBean{" +
                "reqParams='" + reqParams + '\'' +
                ", operatorUserId='" + operatorUserId + '\'' +
                ", updateDate=" + updateDate +
                ", createDate=" + createDate +
                '}';
    }
}